package ee.maoinvest.utils;

import java.util.MissingResourceException;
import java.util.ResourceBundle;
import org.apache.log4j.Logger;
import ee.maoinvest.ErrorMessage;

public class PropertiesFileLoader 
{
	private static final Logger logger = Logger.getLogger(PropertiesFileLoader.class);
	
	private String propertiesFilePath;
	
	public PropertiesFileLoader(String propertiesFilePath) 
	{
		this.propertiesFilePath = propertiesFilePath;
	}
	
	public ResourceBundle getResourceBundleContainingProperties()
	{
		ResourceBundle resourceBundle = null;
		try
		{
			resourceBundle = ResourceBundle.getBundle(propertiesFilePath);
		}
		catch (NullPointerException nullPointerException)
		{
			logger.error(ErrorMessage.ERROR_00001_THE_BASE_NAME_OF_RESOURCE_BUNDLE_IS_NULL 
					+ nullPointerException.getMessage());
		}
		catch (MissingResourceException missingResourceException)
		{
			logger.error(ErrorMessage.ERROR_00002_NO_RESOURCE_BUNDLE_FOR_THE_SPECIFIED_NAME_CAN_BE_FOUND 
					+ missingResourceException.getMessage());
		}
		catch (Exception e)
		{
			logger.error(ErrorMessage.ERROR_00003_UNDEFINED_ERROR_WITH_RESOURCE_BUNDLE_THAT_GETS_PROPERTIES_FILE_DATA 
					+ e.getMessage());
		}
		
		return resourceBundle;
	}
}
